The present invention relates generally to the field of computer mail queues, and more particularly to reserving space in a mail queue in memory from which a processor reads messages.
In computer science, mail queues (a.k.a. message queues) are software-engineering components used for inter-process communication (IPC), or for inter-thread communication within the same process. Mail queues provide an asynchronous communications protocol, meaning that the sender and receiver of a message do not need to interact with the mail queue at the same time. Messages placed onto the queue are stored until the recipient retrieves them. Many implementations of mail queues function internally (i.e., within an operating system or within an application). Mail queues have implicit or explicit limits on the size of data that may be transmitted in a single message and the number of messages that may remain outstanding on the queue. Circular buffering is one strategy for a mail queue that has a fixed maximum size.
A circular buffer (a.k.a. a cyclic buffer or ring buffer) is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. A start pointer and an end pointer respectively identify the start and end of the circular buffer. A fixed number of slots exist between the start pointer and the end pointer. Data can be written to any slot in an empty buffer. Data fills a circular buffer in a direction from start pointer to end pointer, subsequent data being written to a slot that is adjacent to the most recently written to slot. If the slot that is associated with the end pointer is not empty, data is written to the slot that is associated with the start pointer. Writing subsequently stored data to the “beginning” of the circular buffer causes the memory addresses to “wrap around” (i.e., the memory addresses of newer data will have lower values than the memory addresses of older data). Once the buffer is full, slots are overwritten in a direction from the start pointer to the end pointer. In other words, less recently written data is removed from the buffer before more recently written data.